#!/bin/bash

Install_Ruby() {
	#install dependency packages
	for Package in libyaml-devel libffi-devel openssh-server libxslt-devel libicu-devel logrotate python-docutils libkrb5-devel
	do
		yum -y install $Package
	done

	cd $oneinstack_dir/src
	src_url=https://ruby.taobao.org/mirrors/ruby/ruby-$ruby_version.tar.gz && Download_src

	tar xzf ruby-$ruby_version.tar.gz
	cd ruby-$ruby_version
	./configure --disable-install-rdoc --prefix=$ruby_install_dir
	make -j `grep processor /proc/cpuinfo | wc -l`
	make install

	if [ -e "$ruby_install_dir/bin/ruby" ];then
	    cd ..
	    rm -rf ruby-$ruby_version
	    ln -s $ruby_install_dir/bin/ruby /usr/bin/ruby
	    ln -s $ruby_install_dir/bin/bundle /usr/bin/bundle
	    #修改ruby源
	    $ruby_install_dir/bin/gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ 
		$ruby_install_dir/bin/gem sources -l
	    $ruby_install_dir/bin/gem install bundler --no-ri --no-rdoc
	    echo "${CSUCCESS}Ruby install successfully! ${CEND}"
	else
	    rm -rf $ruby_install_dir
	    echo "${CFAILURE}Ruby install failed, Please Contact the author! ${CEND}" 
	    kill -9 $$
	fi

}